package TI;

import java.util.ArrayList;
import java.util.List;

import org.mockito.Matchers;

import Magnitudes.Money;
import Magnitudes.Pesos;
import Products.Presentation;
import Products.Product;

public class Systemo {

	
	private List<BranchOffice> branchOffices;
	private List<ParticularCustomer> customers;
	private List<Product> products;
	private Reporteador reporter;
	private List<String> suscribers;
	
	
	
	
	public Systemo(){
		this.branchOffices = new ArrayList<BranchOffice>();
		this.customers = new ArrayList<ParticularCustomer>();
		this.products = new ArrayList<Product>();
		this.suscribers = new ArrayList<String>();
	}
	
	
	public List<BranchOffice> getBranchOffices(){
		return this.branchOffices;
	}
	
	
	
	
	public void addCustomer(ParticularCustomer customer) {
		this.customers.add(customer);
		suscribers.add(customer.getEmail());
	}




	public void openANewBranchOfficeAt(Address anAddress, Systemo systemToTest) {
		this.branchOffices.add(new BranchOffice(anAddress, systemToTest));		
	}

	public void openANewBranchOfficeWithAStorehouse(Address anAddress,
			Systemo systemToTest) {
		BranchOffice justCreated = new BranchOffice(anAddress, systemToTest);
		this.branchOffices.add(justCreated);
		justCreated.associateStorehouse(new Storehouse(anAddress));
		
	}

	public int numberOfBranchOffices() {		
		return this.getBranchOffices().size();
	}


	public List<Storehouse> getStorehouses() {
		List<Storehouse> sh = new ArrayList<Storehouse>();
		for(BranchOffice branch:this.branchOffices){
			sh.addAll(branch.getStorehouses())	;		
		}
		return sh;
	}


	public void associateStorehouse(Storehouse aStorehouse,
			BranchOffice branchOffice) {
		branchOffice.associateStorehouse(aStorehouse);
		
	}


	public boolean existsClient(Customer anotherCustomer) {
		boolean retVal = false;
		for (ParticularCustomer current:this.customers){
			retVal = (current == anotherCustomer) | retVal;
		}
		return retVal;
	}


	public List<Sale> getAllSales() {
		List<Sale> sales = new ArrayList<Sale>();
		for(BranchOffice branch:this.getBranchOffices()){
			sales.addAll(branch.getSales())	;		
		}
		return sales;
	}


	public void addNewProduct(Product foodstuff) {
		this.products.add(foodstuff);
	}


	public List<Product> getProducts() {
		return this.products;
	}


	public void buyAProduct(Presentation presentation, int i, Pesos fifty,
			BranchOffice aBranchOffice) {
		aBranchOffice.receivePresentations(presentation, i, fifty);
		
	}


	public Money getCashInBranch(BranchOffice aBranchOffice) {
		return aBranchOffice.getCash();
		
	}


	public Money getCashInAllBranches() {
		Pesos cash = new Pesos(0);
		for(BranchOffice bo: this.getBranchOffices()){
			cash.add(getCashInBranch(bo));
		}
		return cash;
	}


	public void notifyOffer(Offer offer) {
		this.sendMail(this.suscribers);
		
	}
	


	private void sendMail(Object suscribers2) {
		// Send mail action
		
	}


	public void removeMailSuscriptionFor(ParticularCustomer aCustomer) {
		this.customers.remove(aCustomer.getEmail());
	}







	
	
	
	
	
	
	
	
	
	
	
	

}
